<?php
	class CriarXls
	{
		public static function execute()
		{
			$conteudo  = '<?php' . "\n\t" . 'session_start();' . "\n\t" . 'set_time_limit(0);' . "\n";
			$conteudo .= "\t" . '$sql = $_SESSION[' . "'" . 'sql' . "'" . '];' . "\n";
			$conteudo .= "\n\t" . 'include_once(' . "'" . '../config/config.inc' . "'" . ');' . "\n";
			$conteudo .= "\n\t" . 'include_once($raiz . ' . "'" . '/connections/banco.inc' . "'" . ');' . "\n";

			$conteudo .= "\t" . 'header(' . "'" . 'Content-Type: application/vnd.ms-excel' . "'" . ');' . "\n";
			$conteudo .= "\t" . 'header(' . "'" . 'Content-Disposition: attachment; filename=plan1.xls' . "'" . ');' . "\n";
			$conteudo .= "\t" . 'header(' . "'" . 'Pragma: no-cache' . "'" . ');' . "\n";
			$conteudo .= "\t" . 'header(' . "'" . 'Expires: 0' . "'" . ');' . "\n";

			$conteudo .= "\n\t" . '$result = ' . $GLOBALS['banco'] . '_query($sql);' . "\n";

			$conteudo .= "\n\t" . 'for ($i = 0; $i < ' . $GLOBALS['banco'] . '_num_fields($result); $i++)' . "\n";
			$conteudo .= "\t" . '{' . "\n\t\t" . 'echo ' . $GLOBALS['banco'] . '_field_name($result, $i) . "\t";' . "\n\t" . '}' . "\n";

			$conteudo .= "\n\t" . 'echo "\n";' . "\n";

		    $conteudo .= "\n\t" . 'while($row = ' . $GLOBALS['banco'] . '_fetch_row($result))' . "\n";
		    $conteudo .= "\t" . '{' . "\n\t\t" . '$conteudo = ' . "'';\n";
		    $conteudo .= "\t\t" . 'for($j = 0; $j < ' . $GLOBALS['banco'] . '_num_fields($result); $j++)' . "\n";
		    $conteudo .= "\t\t" . '{' . "\n\t\t\t" . 'if(empty($row[$j]))' . "\n\t\t\t" . '{' . "\n\t\t\t\t" . '$conteudo .= ' . "''" . ' . "\t";' . "\n";
		    $conteudo .= "\t\t\t" . '}' . "\n\t\t\t" . 'else' . "\n\t\t\t" . '{' . "\n\t\t\t\t" . 'if ($row[$j] != ' . "''" . ')' . "\n";
			$conteudo .= "\t\t\t\t" . '{' . "\n\t\t\t\t\t" . '$conteudo .= $row[$j] . "\t";' . "\n\t\t\t\t" . '}' . "\n";
			$conteudo .= "\t\t\t\t" . 'else' . "\n\t\t\t\t" . '{' . "\n\t\t\t\t\t" . '$conteudo .= ' . "''" . ' . "\t";' . "\n";
			$conteudo .= "\t\t\t\t" . '}' . "\n\t\t\t" . '}' . "\n\t\t" . '}' . "\n";

			$conteudo .= "\t\t" . '$conteudo .= "\t";' . "\n\t\t" . 'echo trim($conteudo);' . "\n\t\t" . 'echo "\n";' . "\n";
		    $conteudo .= "\t" . '}' . "\n" . '?>';

		    return $conteudo;
		}
	}
?>